<?php

class Todo {

    protected $dbo = NULL;

    public function __construct() {

        $this->dbo  = &DBO::getInstance();
    }

    public function addTodo($message) {

        $res = $this->dbo->query("SELECT sys.add_todo(?)",
            array(
                DBString::create($message),
            ));

        throwOnError($res);

        return true;
    }

    public function closeTodo($id) {

        $res = $this->dbo->query("SELECT sys.close_todo(?)",
            array(
                DBInteger::create($id),
            ));

        throwOnError($res);

        return true;
    }

    public function reopenTodo($id) {

        $res = $this->dbo->query("SELECT sys.reopen_todo(?)",
            array(
                DBInteger::create($id),
            ));

        throwOnError($res);

        return true;
    }

    public function deleteTodo($id) {
        
        $res = $this->dbo->query("SELECT sys.delete_todo(?)",
            array(
                DBInteger::create($id),
            ));

        throwOnError($res);

        return true;
    }

    public function getTodo() {

        $res = $this->dbo->getAll("SELECT * FROM sys.todo WHERE NOT deleted ORDER BY done ASC, id ASC", null, DB_FETCHMODE_ASSOC);

        throwOnError($res);

        return $res;
    }
}